﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Quan_Ly_Phong_Kham_co_len_em
{
    public partial class frmkhambenh : Form
    {
        public string _mabnKham;
        public string _tenbnKham;
        public static string _ma;
        public string _xntruyentenbn;
        public DataTable _dtbKB;
        public long _sum;
        public static string _xnTenBN;

        public string chon="";

        public frmkhambenh()
        {
            InitializeComponent();
            DataGridViewTextBoxColumn col = new DataGridViewTextBoxColumn();

           // TV_Tonghop.Themcot("STT", "Số Thứ Tự", dt_khambenh, DataGridViewAutoSizeColumnMode.Fill);

            TV_Tonghop.Themcot("Ma_LoaiXN", "Mã loại xn", dt_khambenh, DataGridViewAutoSizeColumnMode.Fill);
            TV_Tonghop.Themcot("Ten_LoaiXN", "Tên loại xn", dt_khambenh, DataGridViewAutoSizeColumnMode.Fill);
            TV_Tonghop.Themcot("Don_Gia", "Đơn giá", dt_khambenh, DataGridViewAutoSizeColumnMode.Fill);
            TV_Tonghop.Themcot("Ngay_Ap_Dung", "Ngày Áp Dụng", dt_khambenh, DataGridViewAutoSizeColumnMode.Fill);
           // TV_Tonghop.Themcot("Tong_tien", "Tổng Tiền Dịch Vụ", dt_khambenh, DataGridViewAutoSizeColumnMode.Fill);
        }

        private void groupPanel1_Click(object sender, EventArgs e)
        {

        }

        public SqlConnection getconnect()
        {
            return new SqlConnection("Data Source=NGUYENTY-PC\\SQLEXPRESS;Initial Catalog=QL_PHONGKHAM;Integrated Security=True");

        }        

        private void frmkhambenh_Load(object sender, EventArgs e)
        {
            if (chon == "") return;
            SqlConnection ketnoi = getconnect();
            ketnoi.Open();
            SqlCommand cmd = new SqlCommand(@"  SELECT * FROM LOAI_XET_NGHIEM_MAU WHERE TEN_LOAIXN IN (" + chon + ")", ketnoi);

            var TB = new DataTable();
            TB.Load(cmd.ExecuteReader());

            _sum = Convert.ToInt64(TB.Compute("sum(don_gia)", ""));
            txtTongtien.Text = _sum + "";
            dt_khambenh.DataSource = TB; 
                

           // _ma = _mabnKham.Trim();
           
           // SqlConnection ketnoi = new SqlConnection("Data Source=NGUYENTY-PC\\SQLEXPRESS;Initial Catalog=QL_PHONGKHAM;Integrated Security=True");
           // ketnoi.Open();
           // SqlCommand cmd = new SqlCommand(@"Select * From Benh_Nhan Where Ma_BN = '" + _ma + "' ", ketnoi);
           // DataTable dt = new DataTable();
           // dt.Load(cmd.ExecuteReader());
           // txb_mabenhnhan.Text = dt.Rows[0]["Hoten_BN"] + "";

           // // load du lieu vao datagridview
           // SqlCommand cmd1 = new SqlCommand(@"select a.STT,a.Dich_Vu,a.Ngay_Ap_Dung_DV,a.Tong_tien,b.HOTEN_BN from Su_DungDV a join BENH_NHAN b on a.Ma_BN=b.MA_BN Where a.Ma_BN='" + _ma + "'", ketnoi);
           ////SqlCommand cmd1 = new SqlCommand(@"Select * From #temp", ketnoi);
           //DataTable dt1 = new DataTable(); 
           // dt1.Load(cmd1.ExecuteReader()); 

           // dt_khambenh.DataSource = dt1; 
           
        }

     
        private void textBoxX20_TextChanged(object sender, EventArgs e)
        {

        }

        private void cb_xetnghiemmau_CheckedChanged(object sender, EventArgs e)
        {
            _xnTenBN = _tenbnKham;
            if (cb_xetnghiemmau.CheckState == CheckState.Checked)
            {
                frmxetnghiem xetnghiem = new frmxetnghiem();
                xetnghiem._xnTenBN = _xnTenBN;                
                xetnghiem.ShowDialog();
            }
            else
            {
                this.Show();
            }
        }

        private void bt_ToaThuoc_Click(object sender, EventArgs e)
        {
            frmdonthuoc donthuoc = new frmdonthuoc();
            donthuoc._maBN = _mabnKham;
            donthuoc._tenBN = txb_mabenhnhan.Text;
            donthuoc.Show();
        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            frmkhambenh_Load(sender, e);
            txb_mabenhnhan.Text = _xntruyentenbn;
        }

        private void cb_XQuangCT_CheckedChanged(object sender, EventArgs e)
        {
            frmXquang_CT XQuangCT = new frmXquang_CT();
            XQuangCT.ShowDialog();
        }

        private void cb_sieuam_CheckedChanged(object sender, EventArgs e)
        {
            frmsieuam sieuam = new frmsieuam();
            sieuam.ShowDialog();
        }
    }
}
